package com.ruoyi.system.controller;

import com.ruoyi.system.service.MarkdownService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/system/MarkDown")
public class MarkdownController {

    @Autowired
    private MarkdownService markdownService;

    @PostMapping("/process-markdown")
    public ResponseEntity<String> processMarkdown(@RequestBody Map<String, String> request) {
        String minioEndpoint = request.get("minioEndpoint");
        String accessKey = request.get("accessKey");
        String secretKey = request.get("secretKey");
        String bucketName = request.get("bucketName");
        String markdownFilePath = request.get("markdownFilePath");

        if (minioEndpoint == null || accessKey == null || secretKey == null || bucketName == null || markdownFilePath == null) {
            return ResponseEntity.badRequest().body("Missing required parameters");
        }

        try {
            markdownService.processMarkdown(minioEndpoint, accessKey, secretKey, bucketName, markdownFilePath);
            return ResponseEntity.ok("Markdown file processed successfully");
        } catch (Exception e) {
            return ResponseEntity.internalServerError().body("Failed to process Markdown file: " + e.getMessage());
        }
    }
}